package com.muyu.danmo.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.danmo.domain.DanmoBackPicture;
import com.muyu.danmo.service.IDanmoBackPictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 背景图片Controller
 * 
 * @author yangle
 * @date 2025-03-08
 */
@RestController
@RequestMapping("/backPicture")
public class DanmoBackPictureController extends BaseController
{
    @Autowired
    private IDanmoBackPictureService danmoBackPictureService;

    /**
     * 查询背景图片列表
     */
//    @RequiresPermissions("system:backPicture:list")
    @PostMapping("/list")
    public Result<TableDataInfo<DanmoBackPicture>> list(@RequestBody DanmoBackPicture danmoBackPicture)
    {
        startPage();
        List<DanmoBackPicture> list = danmoBackPictureService.selectDanmoBackPictureList(danmoBackPicture);
        return getDataTable(list);
    }

    /**
     * 导出背景图片列表
     */
//    @RequiresPermissions("system:backPicture:export")
    @Log(title = "背景图片", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoBackPicture danmoBackPicture)
    {
        List<DanmoBackPicture> list = danmoBackPictureService.selectDanmoBackPictureList(danmoBackPicture);
        ExcelUtil<DanmoBackPicture> util = new ExcelUtil<DanmoBackPicture>(DanmoBackPicture.class);
        util.exportExcel(response, list, "背景图片数据");
    }

    /**
     * 获取背景图片详细信息
     */
//    @RequiresPermissions("system:backPicture:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoBackPictureService.selectDanmoBackPictureById(id));
    }

    /**
     * 新增背景图片
     */
//    @RequiresPermissions("system:backPicture:add")
    @Log(title = "背景图片", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DanmoBackPicture danmoBackPicture)
    {
        return toAjax(danmoBackPictureService.insertDanmoBackPicture(danmoBackPicture));
    }

    /**
     * 修改背景图片
     */
//    @RequiresPermissions("system:backPicture:edit")
    @Log(title = "背景图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoBackPicture danmoBackPicture)
    {
        return toAjax(danmoBackPictureService.updateDanmoBackPicture(danmoBackPicture));
    }

    /**
     * 删除背景图片
     */
//    @RequiresPermissions("system:backPicture:remove")
    @Log(title = "背景图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(danmoBackPictureService.deleteDanmoBackPictureByIds(ids));
    }


    /**
     * 查询单个图片并渲染颜色
     */
    @PostMapping("/getPicture")
    public Result getPicture(@RequestBody DanmoBackPicture danmoBackPicture) {
        return success(danmoBackPictureService.getPicture(danmoBackPicture));
    }
}
